package app

import (
	"fmt"

	"github.com/wonderivan/logger"
)

func GetPartnerStr(companyId int) string {
	return fmt.Sprintf(`company_%d_Partner`, companyId)
}

func JudgePartnerTable(companyId int) error {
	// myrpc.QuerySql()

	// _, err := mysql.CusSql.QueryIdlimit1(GetPartnerStr(companyId))
	// if err != nil {
	// 	err = createPartnerTable(companyId)
	// }
	// return err
	return nil
}

func createPartnerTable(companyId int) error {
	sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) UNIQUE,
update_user_id char(255),
create_time datetime  DEFAULT NOW(),
update_time datetime  ON UPDATE NOW()
)
`, GetPartnerStr(companyId))
	// _, err := mysql.CusSql.DB.Exec(sql)
	logger.Info(sql)
	return nil
}

type PartnerFrom struct {
	Company_id     int    `form:"company_id" binding:"required"`
	Id             int    `form:"id"`
	Name           string `form:"name"`           //名称
	Update_user_id int    `form:"update_user_id"` //更新人ID 不传
}
